package com.business.action.wechat;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.wechat.bean.WeixinConfigBean;

import net.sf.rose.jdbc.PageBean;
import net.sf.rose.jdbc.dao.BeanDAO;
import net.sf.rose.jdbc.query.BeanSQL;
import net.sf.rose.jdbc.service.Service;
import net.sf.rose.web.util.WebUtils;

@Controller
@RequestMapping("/weixin/config")
public class WechatConfigAction {

	/**
	 * 查询列表
	 */
	@ResponseBody
	@RequestMapping("/list.do")
	public PageBean list(HttpServletRequest request, Service service) {
		PageBean page = WebUtils.getPageBean(request);
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.setEntityClass(WeixinConfigBean.class);
		query.setPage(page);
		query.createSql(WebUtils.getRequestData(request));
		dao.list();
		return page;
	}

	/**
	 * 
	 */
	@ResponseBody
	@RequestMapping("/get.do")
	public WeixinConfigBean get(HttpServletRequest request, Service service) {
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.setEntityClass(WeixinConfigBean.class);
		query.createSql(WebUtils.getRequestData(request));
		return dao.get();
	}

	/**
	 * 保存配置
	 */
	@ResponseBody
	@RequestMapping("/save.do")
	public PageBean save(HttpServletRequest request, Service service, WeixinConfigBean bean) {
		PageBean res = new PageBean();
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.createSaveSql(bean);
		int i = dao.update();
		if (i > 0) {
			res.setMessage("保存配置信息成功！");
		} else {
			res.setMessage("保存配置信息失败");
		}
		return res;
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete.do")
	public PageBean delete(HttpServletRequest request, Service service, String id) {
		PageBean page = new PageBean();
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.createDeleteSql(WeixinConfigBean.class, id);
		if (!dao.execute()) {
			page.setSuccess(false);
			page.setMessage("没有一条数据被删除！");
		}
		return page;
	}
}
